Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate incidents creation #586

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

JenySadadia
Copy link
Collaborator

Automate the creation of incidents based on issues using kcidb_match tool.

@JenySadadia JenySadadia force-pushed the auto-create-incidents branch 2 times, most recently from e41e75b to b2c5392 Compare October 3, 2024 13:31
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Show resolved Hide resolved
@JenySadadia
Copy link
Collaborator Author

@helen-fornazier Thanks for the comments.
It would have been easier if you had committed the changes directly to this PR.
But no worries, I'll do it.

@JenySadadia JenySadadia force-pushed the auto-create-incidents branch 2 times, most recently from 7f7da72 to 0fe4538 Compare October 4, 2024 07:35
Copy link

@tales-aparecida tales-aparecida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so happy with how fast this is moving

kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
@JenySadadia JenySadadia force-pushed the auto-create-incidents branch 2 times, most recently from 1a29241 to a5f7531 Compare October 14, 2024 13:37
@helen-fornazier
Copy link
Collaborator

Proposal for command line tool usage:

cat issue.json | kcidb-issues --pattern-db-file=DB_NAME # this would save the patterns in `DB_NAME`

cat tests.json | kcidb-issues --pattern-db-file=DB_NAME # this would dump a json with the incidents (if it was created) matched agains `DB_NAME`

with this, we can use this tool to debug, and also to validate a issue and test example in the editor UI before submitting it to kcidb

@tales-aparecida @JenySadadia @spbnick what do you think?

so we can drop all the options I had previously added there

@helen-fornazier
Copy link
Collaborator

Proposal for command line tool usage:

cat issue.json | kcidb-issues --pattern-db-file=DB_NAME # this would save the patterns in `DB_NAME`

cat tests.json | kcidb-issues --pattern-db-file=DB_NAME # this would dump a json with the incidents (if it was created) matched agains `DB_NAME`

with this, we can use this tool to debug, and also to validate a issue and test example in the editor UI before submitting it to kcidb

@tales-aparecida @JenySadadia @spbnick what do you think?

so we can drop all the options I had previously added there

Following up this comment #586 (comment)

I think we can leave it to a second PR, no problem for me

kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@spbnick spbnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to leave a possibly overwhelming review, asking to change things a lot. Let's discuss this and see what's viable at this moment. However, this would all be for nothing if I don't fix that performance problem I was working on before Plumbers, and don't enable notifications. This code would simply not be called without that. So I'll go and work on that, instead of going further into detailed review 🙈

kcidb/tools/kcidb_match.py Outdated Show resolved Hide resolved
If snippet_lines == 0: the full log
If snippet_lines > 0: the first snippet_lines log lines
If snippet_lines < 0: the last snippet_lines log lines
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please document classes/methods/functions fully, including the arguments, following the conventions seen everywhere else in the code? Also, if you have a multi-line docstring, could you please start the text on the next line from the """? Thank you 🙏

"""
try:
response = requests.get(url, timeout=60)
response.raise_for_status()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you could try to fetch the URL from the artifact cache first? Similarly to how it's done in the cache redirector:

kcidb/main.py

Lines 576 to 577 in 37961dc

cache_client = get_cache_client()
cache = cache_client.map(url_to_fetch, ttl=CACHE_REDIRECT_TTL)

This way we could save a little of inbound traffic now, and once we have cache fully working we could save a lot.

return None
try:
raw_bytes = gzip.decompress(response.content)
text = raw_bytes.decode('utf-8')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary, nor possible, as the log URL should point to a plain log file. This should be fixed in Maestro. E.g. by configuring the web server to specify Transfer-Encoding: gzip and serving the files compressed transparently. Python requests would then decompress that automatically. Otherwise this not only hurts our code complexity, but also the experience of users who download those files and then have to decompress them manually.

@nuclearcat, @pawiecz, how hard would that be to fix?

"""Pattern validator class"""
def __init__(self):
self.schema = copy.deepcopy(kcidb.io.SCHEMA.json)
self.remove_required_fields(self.schema)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a class at all. You don't need multiple of them and it doesn't have any parameters. Please remake it into a module (this or a separate one). Also, it doesn't only validate patterns.

kcidb_io_object = {"tests": [test._data],
"builds": [test.build._data],
"checkouts": [test.build.checkout._data]}
return self.generate_incidents_from_db(kcidb_io_object)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot make an I/O object from an OO object in general, even if it looks like you can. You just cannot count on that. An OO object is a processed I/O object, and there can be data loss. Instead deal with OO objects directly everywhere. Where you need to process I/O objects from stdin and command-line interface, load them into an sqlite database using the database client, get them as OO objects from there, and then process.

OO objects were specifically made to make the things you're doing here easier to do. Like walk related objects and so on. We can have a call this week and go over all the concerns and options regarding this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, there's also a schema for the raw OO data in kcidb.orm.data.

client = get_client()
if client:
incident_generator = kcidb_match.IncidentGenerator()
incidents = incident_generator.generate_incidents_from_test(test)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that IncidentGenerator encapsulates a database client connection, why not create and get it similarly to get_client(), instead of creating a new one for every object matched?

helen-fornazier and others added 2 commits October 17, 2024 16:26
Add `tools` directory and add `kcidb_match.py` script
there.

Co-authored-by: Jeny Sadadia <[email protected]>
Signed-off-by: Jeny Sadadia <[email protected]>
Add a subscription module `create_incidents.py` to
create incidents automatically when builds and tests
objects match with issue patterns.

Signed-off-by: Jeny Sadadia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants